var GamePlay = function(settings){

this.gameSetup 			= new GameSetupXmlReader("./standardgame.xml");

this.level 				= settings.level;
this.patternOdds 		= settings.patternOdds;

this.patternSize		= this.gameSetup.getPatternSize(this.level);
this.nBack				= this.gameSetup.getNBack(this.level);
this.turns				= this.gameSetup.getTurns(this.level)+this.nBack;

this.timePerTurn		= ((this.nBack*this.nBack)+this.patternSize)*1000*(1/settings.difficulty);
this.timeUsedPerTurn	= 0;
this.turnsWent			= 0;
this.mistakes			= 0;
this.timeSpent = 0;

this.timesRegress = 0;
this.timesProgress = 0;

this.update = function(){
this.patternSize		= this.gameSetup.getPatternSize(this.level);
this.nBack				= this.gameSetup.getNBack(this.level);
this.turns				= this.gameSetup.getTurns(this.level)+this.nBack;

this.timePerTurn		= ((this.nBack*this.nBack)+this.patternSize)*1000*(1/settings.difficulty);
this.timeUsedPerTurn	= 0;
this.turnsWent			= 0;
this.mistakes			= 0;
this.timeSpent = 0;
}
	
	this.startTimer = function(){
	this.startTime			= new Date();	
	}
	this.moveTurn = function(correct){
		if(!correct)
		{
		this.mistakes++;
		}
		else
		{
		this.turnsWent++;
		}
		if(this.turnsWent===this.turns)
		{
		this.timeSpent = new Date()-this.startTime
		return false;
		}
	return true;
	}
	
	this.clean = function(){
	this.timeUsedPerTurn	= 0;
	this.turnsWent			= 0;
	this.mistakes			= 0;
	this.timeSpent = 0;
	}
	this.reportCorrect = function(percentageCorrect){
		if(percentageCorrect>this.gameSetup.percentageProgress)
		{
		this.timesProgress++;
		this.timesRegress=0;
		}
		else if (percentageCorrect<this.gameSetup.percentageRegress)
		{
		this.timesRegress++;
		this.timesProgress=0;
		}
		
		if(this.timesProgress>(this.gameSetup.timesProgress-1) && this.level<this.gameSetup.getLevels().length)
		{
		this.level++;
		this.timesRegress = 0;
		this.timesProgress = 0;
		}
		else if(this.timesRegress>(this.gameSetup.timesRegress-1) && this.level>0)
		{
		this.level--;
		this.timesRegress = 0;
		this.timesProgress = 0;
		}
	this.update();
	}
	
}